package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppComment;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 评论回复
 */
@Repository
public class AfterCommentReplyDao extends BaseDao<AppCommentReply> {

    /**
     * 查询列表
     */
    public List<AppCommentReply> list(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_comment_reply where 1=1  ");

        if (StringEx.isNotNull(paraMap.get("commentid"))) {
            sbStr.append(" and commentid = ? ");
            paramList.add(paraMap.get("commentid"));
        }

        if (StringEx.isNotNull(paraMap.get("nick"))) {
            sbStr.append(" and nick = ? ");
            paramList.add(paraMap.get("nick"));
        }

        if (StringEx.isNotNull(paraMap.get("phone"))) {
            sbStr.append(" and phone = ? ");
            paramList.add(paraMap.get("phone"));
        }


        if (StringEx.isNotNull(paraMap.get("replynick"))) {
            sbStr.append(" and replynick = ? ");
            paramList.add(paraMap.get("replynick"));
        }

        if (StringEx.isNotNull(paraMap.get("replyphone"))) {
            sbStr.append(" and replyphone = ? ");
            paramList.add(paraMap.get("replyphone"));
        }
        if (StringEx.isNotNull(paraMap.get("status"))) {
            sbStr.append(" and status = ? ");
            paramList.add(paraMap.get("status"));
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppCommentReply.class, splitPage);
    }


    /**
     * 详情
     */
    public AppCommentReply get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_comment_reply where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppCommentReply.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppCommentReply haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_comment_reply where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 更新状态(逻辑删除)
     * @param id
     * @param status
     */
    public void updateStatus(Integer id, Integer status) {
        if (id <= 0) {
            return;
        }
        String sql = "update app_comment_reply set status = ?  where id = ? ";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(status);
        paramList.add(id);
        this.update(sql, paramList);
    }

}
